package com.lyl.projectspringboot.controller;

import com.lyl.projectspringboot.dto.UserDto;
import com.lyl.projectspringboot.dto.dtoMapper.UserMapper;
import com.lyl.projectspringboot.entity.User;
import com.lyl.projectspringboot.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    private final UserMapper userMapper;

    //测试（查询所有用户）
    @GetMapping("/getAllUser")
    public List<User> getAllUser(){
        return userService.list();
    }

    //测试（根据用户uid查询用户）
    @GetMapping("/findUserByUid/{uid}")
    public UserDto getUserByUid(@PathVariable Integer uid){
        return userMapper.toDto(userService.getById(uid));
    }


    @GetMapping("/findUserById/{id}")
    public UserDto getUserById(@PathVariable String id){
        return userService.getUserDtoById(id);
    }

    @GetMapping("/getAllUserOrderById")
    public List<UserDto> getAllUserOrderById(@RequestParam Long pageNo, @RequestParam Long pageSize){
        return userService.getAllUserOrderById(pageNo,pageSize);
    }

    @PutMapping("/updateUserById")
    public boolean updateUserById(@RequestBody UserDto userDto){
        return userService.UpdateUserById(userDto);
    }


}
